package com.juyu.miliao.api.service;

import com.juyu.miliao.api.dao.mysql.FindDynamicInfoChannelDao;
import com.juyu.miliao.api.domain.FindDynamicInfoChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * @author xuanqicheng
 */
@Service
public class FindDynamicInfoChannelService {

    @Autowired
    private FindDynamicInfoChannelDao findDynamicInfoChannelDao;

    /**
     * 检查渠道屏蔽度状态
     * @param channelId
     * @return
     *         false 不屏蔽
     *         true 屏蔽
     */
    public boolean getShieldType(String channelId){
        boolean bl = false;
        FindDynamicInfoChannel findDynamicInfoChannel =findDynamicInfoChannelDao
                .getFindDynamicInfoChannelByChannelId(channelId);
        if(findDynamicInfoChannel!=null){
            LocalTime startTime = findDynamicInfoChannel.getStartTime();
            LocalTime endTime = findDynamicInfoChannel.getEndTime();
            //判断开始于结束时间是否跨天
            if(startTime.isAfter(endTime)){
                LocalTime nowTime = LocalTime.now();
                if(nowTime.isAfter(startTime)||nowTime.equals(startTime)){
                    bl = true;
                }else if(nowTime.isBefore(endTime)||nowTime.equals(endTime)){
                    bl = true;
                }
            }else if(startTime.isBefore(endTime)){
                LocalTime nowTime = LocalTime.now();
                if(nowTime.isAfter(startTime)||nowTime.equals(startTime)){
                    if(nowTime.isBefore(endTime)||nowTime.equals(endTime)){
                        bl=true;
                    }
                }
            }else{
                LocalTime nowTime = LocalTime.now();
                if(nowTime.equals(startTime)&&nowTime.equals(endTime)){
                    bl = true;
                }
            }
        }
        return bl;
    }

}
